/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Main.java
 *
 * Created on Sep 25, 2011, 5:54:32 AM
 */
package azhar.view;

import azhar.com.PropertiesFile;
import azhar.engine.MessageService;
import azhar.database.DatabaseController;
import azhar.engine.SoundNotification;
import azhar.view.com.Config;
import azhar.view.com.GlassLoading;
import azhar.view.com.GlassLock;
import azhar.view.com.SendProcess;
import azhar.view.com.SignalStatus;
import java.awt.Image;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import org.smslib.InboundMessage;
import org.smslib.OutboundMessage;
import org.smslib.OutboundMessage.MessageStatuses;

/**
 *
 * @author Al-Insan
 */
public class Main extends javax.swing.JFrame {

    private MessageService service;
    private List<InboundMessage> readMessage;
    private GlassLoading loading;
    public Contacts tabContact;
    private Messages tabMessage;
    public DatabaseController dbControl;
    public ArrayList[] dtGuru;
    public ArrayList[] dtKaryawan;
    public ArrayList[] dtSiswa;
    public ArrayList[] dtInbox;
    public ArrayList[] dtOutbox;
    public ArrayList[] dtDraft;
    public ArrayList[] dtSentItem;
    private int count = 0;
    private GlassLock lock;
    private SignalStatus sl;
    private int indicator = 0;
    private SendProcess sending;

    /** Creates new form Main */
    public Main() {
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(mainPanel, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
        }
        setIconImage(new ImageIcon(getClass().getResource("images/logo.png")).getImage());
        load();
        tabContact = new Contacts(this);
        tabMessage = new Messages(this);

        lock = new GlassLock(this);
        initComponents();
        mainPanel.add(tabContact, "2");
        mainPanel.add(tabMessage, "3");
        tabContact.setVisible(false);
        tabMessage.setVisible(false);
        contact.setEnabled(false);
        message.setEnabled(false);
        sl = new SignalStatus(this);
        lbin.setVisible(false);
        SwingUtilities.invokeLater(new Runnable() {

            public void run() {
                setGlassPane(lock);
                getGlassPane().setVisible(true);
                lock.setBlock(true);
            }
        });
        validate();
    }

    public String getPass() {
        PropertiesFile prop = null;
        try {
            prop = new PropertiesFile();
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(mainPanel, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
        }
        return prop.getValue("drowssap");
    }

    public void load() {
        Loading load = new Loading();
        load.setVisible(true);
        load.setValue(1, 20);
        load.setValue(21, 40);
        dbControl = new DatabaseController();
        load.setValue(41, 50);
        dtGuru = dbControl.getDatasGuru();
        dtInbox = dbControl.getDatasInbox();
        load.setValue(51, 70);
        dtKaryawan = dbControl.getDatasKaryawan();
        dtOutbox = dbControl.getDatasOutbox();
        dtDraft = dbControl.getDatasDraft();
        load.setValue(71, 80);
        dtSiswa = dbControl.getDatasSiswa();
        dtSentItem = dbControl.getDatasSent();
        load.setValue(81, 100);
        load.close();
    }

    public void initMessage() throws Exception {
        service.printGatewayInfo();
        System.out.println("STATUS --> Initializing Message");
        detect.setActionCommand("stop");
        detect.setText("Stop Service");
        contact.setEnabled(true);
        message.setEnabled(true);
        welcomePanel.setVisible(false);
        tabContact.setVisible(true);
    }

    public void readMessage(InboundMessage msg) {
        if (msg.getMemLocation().equals("ME")) {
            try {
                setMessageIndicator(indicator++);
                String[] data = {"+" + msg.getOriginator(), msg.getText(), msg.getDate().toGMTString(), msg.getSmscNumber()};
                tabMessage.addData("inbox", data);
                new SoundNotification().playInboxSound();
            } catch (Exception ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public void signal(int i) {
        if (i > -1) {
            sng.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/level_empty.png")));
        } else if (i < 0 && i > -21) {
            sng.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/level_1.png")));
        } else if (i < -20 && i > -41) {
            sng.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/level_2.png")));
        } else if (i < -40 && i > -61) {
            sng.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/level_3.png")));
        } else if (i < -60 && i > -91) {
            sng.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/level_4.png")));
        } else if (i < -90) {
            sng.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/level_5.png")));
        }
        validate();
    }

    public void battery(int i) {
        if (i < 1) {
            bat.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/battery_empty.png")));
        } else if (i > 0 && i < 21) {
            bat.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/battery_level1.png")));
        } else if (i > 20 && i < 41) {
            bat.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/battery_level2.png")));
        } else if (i > 40 && i < 61) {
            bat.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/battery_level3.png")));
        } else if (i > 60 && i < 81) {
            bat.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/battery_level4.png")));
        } else if (i > 80 && i < 91) {
            bat.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/battery_level5.png")));
        } else if (i > 90 && i < 101) {
            bat.setIcon(new javax.swing.ImageIcon(getClass().getResource("images/battery_full.png")));
        }
        validate();
    }

    public void setGatewayStatus(String stat){
        gatewayStat.setText("Gateway Status: "+stat);
    }

    public MessageService getService() {
        return service;
    }

    public void setService(MessageService ms) throws Exception {
        service = ms;
    }

    public void setModemInfo(String info) {
        lbModem.setText(info);
    }

    public int getBattery() throws Exception {
        return service.getBatteryLevel();
    }

    public int getSignal() throws Exception {
        return service.getSignalLevel();
    }

    public void setBattery() {
        sl.start();
    }

    public void releaseBattery() {
        sl.stop();
    }

    public void setMessageIndicator(int in) {
        indicator += in;
        if (indicator > 0) {
            lbin.setVisible(true);
        } else {
            lbin.setVisible(false);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        contact = new javax.swing.JButton();
        message = new javax.swing.JButton();
        detect = new javax.swing.JButton();
        detect1 = new javax.swing.JButton();
        status = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        signal = new javax.swing.JPanel();
        sng = new javax.swing.JLabel();
        battery = new javax.swing.JPanel();
        bat = new javax.swing.JLabel();
        lbModem = new javax.swing.JLabel();
        lbin = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        gatewayStat = new javax.swing.JLabel();
        mainPanel = new javax.swing.JPanel();
        welcomePanel = new javax.swing.JPanel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("SMS Center");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(153, 153, 153));

        contact.setText("Contacts");
        contact.setOpaque(false);
        contact.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                contactActionPerformed(evt);
            }
        });

        message.setText("Messages");
        message.setOpaque(false);
        message.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                messageActionPerformed(evt);
            }
        });

        detect.setFont(new java.awt.Font("Tahoma", 0, 9));
        detect.setText("Detect Modem");
        detect.setActionCommand("detect");
        detect.setBorder(null);
        detect.setBorderPainted(false);
        detect.setOpaque(false);
        detect.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                detectActionPerformed(evt);
            }
        });

        detect1.setFont(new java.awt.Font("Tahoma", 0, 9));
        detect1.setText("Lock");
        detect1.setActionCommand("detect");
        detect1.setBorder(null);
        detect1.setBorderPainted(false);
        detect1.setOpaque(false);
        detect1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                detect1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(contact)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(message, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(342, 342, 342)
                .addComponent(detect, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addComponent(detect1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(contact)
                    .addComponent(detect, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(detect1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(message))
                .addContainerGap(15, Short.MAX_VALUE))
        );

        status.setBackground(new java.awt.Color(153, 153, 153));
        status.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/azhar/view/images/signal.png"))); // NOI18N
        status.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(42, 10, -1, 26));

        signal.setOpaque(false);
        signal.setLayout(new java.awt.CardLayout());

        sng.setIcon(new javax.swing.ImageIcon(getClass().getResource("/azhar/view/images/level_empty.png"))); // NOI18N
        signal.add(sng, "card2");

        status.add(signal, new org.netbeans.lib.awtextra.AbsoluteConstraints(55, 10, 30, 26));

        battery.setOpaque(false);
        battery.setLayout(new java.awt.CardLayout());

        bat.setIcon(new javax.swing.ImageIcon(getClass().getResource("/azhar/view/images/battery_empty.png"))); // NOI18N
        battery.add(bat, "card2");

        status.add(battery, new org.netbeans.lib.awtextra.AbsoluteConstraints(16, 8, 14, 30));

        lbModem.setFont(new java.awt.Font("Tahoma", 1, 11));
        status.add(lbModem, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 10, 238, 26));

        lbin.setOpaque(false);
        lbin.setLayout(new java.awt.CardLayout());

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/azhar/view/images/message_in.png"))); // NOI18N
        jButton1.setBorder(null);
        jButton1.setBorderPainted(false);
        jButton1.setContentAreaFilled(false);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        lbin.add(jButton1, "card2");

        status.add(lbin, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 10, 30, 20));
        status.add(gatewayStat, new org.netbeans.lib.awtextra.AbsoluteConstraints(390, 7, 190, 30));

        mainPanel.setLayout(new java.awt.CardLayout());

        javax.swing.GroupLayout welcomePanelLayout = new javax.swing.GroupLayout(welcomePanel);
        welcomePanel.setLayout(welcomePanelLayout);
        welcomePanelLayout.setHorizontalGroup(
            welcomePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 701, Short.MAX_VALUE)
        );
        welcomePanelLayout.setVerticalGroup(
            welcomePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 336, Short.MAX_VALUE)
        );

        mainPanel.add(welcomePanel, "1");

        jMenu1.setText("File");

        jMenuItem3.setText("Change Password");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        jMenuItem2.setText("Exit");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        jMenu2.setText("Help");

        jMenuItem1.setText("About");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem1);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 701, Short.MAX_VALUE)
            .addComponent(status, javax.swing.GroupLayout.DEFAULT_SIZE, 701, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 336, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(status, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-717)/2, (screenSize.height-501)/2, 717, 501);
    }// </editor-fold>//GEN-END:initComponents

    private void detectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detectActionPerformed
        if (detect.getActionCommand().equals("detect")) {
            loading = new GlassLoading(this);
            loading.setBlock(true);
            setGlassPane(loading);
            getGlassPane().setVisible(true);
            loading.serching();
            sending = new SendProcess(this, false);
        } else if (detect.getActionCommand().equals("stop")) {
            if (count < 1) {

                loading.setText("stopping service");
                loading.setBlock(true);
                setGlassPane(loading);
                getGlassPane().setVisible(true);
                Runnable load = new Runnable() {

                    public void run() {
                        try {
                            loading.stopService();
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(mainPanel, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                };
                SwingUtilities.invokeLater(load);
                detect.setText("Exit");
                detect.setActionCommand("exit");
                tabContact.setVisible(false);
                tabMessage.setVisible(false);
                welcomePanel.setVisible(true);
            } else {
                JOptionPane.showMessageDialog(rootPane, "Service can't be stopped, because other process is still running", "WARNING", JOptionPane.WARNING_MESSAGE);
            }
        } else if (detect.getActionCommand().equals("start")) {
            try {
                loading.setText("starting service");
                loading.setBlock(true);
                setGlassPane(loading);
                getGlassPane().setVisible(true);
                Runnable load = new Runnable() {

                    public void run() {
                        try {
                            loading.startService();
                        } catch (Exception ex) {
                            JOptionPane.showMessageDialog(mainPanel, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                };
                SwingUtilities.invokeLater(load);
                detect.setText("Stop Service");
                detect.setActionCommand("stop");
                tabContact.setVisible(true);
                tabMessage.setVisible(false);
                welcomePanel.setVisible(false);
            } catch (Exception ex) {
                JOptionPane.showMessageDialog(mainPanel, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
            }
        } else {
            close();
        }
    }//GEN-LAST:event_detectActionPerformed

    private void detect1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_detect1ActionPerformed
        setGlassPane(lock);
        lock.setBlock(true);
        getGlassPane().setVisible(true);
    }//GEN-LAST:event_detect1ActionPerformed

    private void contactActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contactActionPerformed
        tabContact.setVisible(true);
        tabMessage.setVisible(false);
    }//GEN-LAST:event_contactActionPerformed

    private void messageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_messageActionPerformed
        tabContact.setVisible(false);
        tabMessage.setVisible(true);
    }//GEN-LAST:event_messageActionPerformed

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        close();
    }//GEN-LAST:event_formWindowClosing

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        new About(this, false).setVisible(true);
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        close();
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        tabMessage.readInbox();
        tabContact.setVisible(false);
        tabMessage.setVisible(true);
        lbin.setVisible(false);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        try {
            new Config(this, false).setVisible(true);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(mainPanel, ex.getMessage(), "ERROR", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jMenuItem3ActionPerformed
    public void close() {
        if (count < 1) {
            System.exit(0);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Application can't be closed, because other process is still running", "WARNING", JOptionPane.WARNING_MESSAGE);
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        new Main().setVisible(true);
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bat;
    private javax.swing.JPanel battery;
    private javax.swing.JButton contact;
    private javax.swing.JButton detect;
    private javax.swing.JButton detect1;
    private javax.swing.JLabel gatewayStat;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel lbModem;
    private javax.swing.JPanel lbin;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JButton message;
    private javax.swing.JPanel signal;
    private javax.swing.JLabel sng;
    private javax.swing.JPanel status;
    private javax.swing.JPanel welcomePanel;
    // End of variables declaration//GEN-END:variables

    public void sendMessage(ArrayList<azhar.com.Messages> mes) throws Exception {
        if (count < 1) {
//            System.out.println(mes.get(1).getNumber());
        new SendProcess(this, true).addMessage(mes);
        } else {
            JOptionPane.showMessageDialog(rootPane, "Message can't be processed, because other process is still running", "WARNING", JOptionPane.WARNING_MESSAGE);
        }
    }

    public void setProcess(int c) {
        count = c;
    }

    public void sendingMessage(String text, String text0) throws Exception {
        OutboundMessage out = service.sendMessage(text, text0);
        String no = out.getRecipient();
        String t = out.getText();
        if (out.getMessageStatus().equals(MessageStatuses.SENT)) {
            String[] data = {out.getRecipient(), out.getText(), "SENT", out.getDate().toGMTString()};
            tabMessage.addData("sentItem", data);
        } else {
            new SoundNotification().playErrorSound();
            String[] data = {no, t, "FAILED"};
            tabMessage.addData("outbox", data);
        }
    }

    public void save(String text, String text0) {
        String[] data = {text, text0};
        tabMessage.addData("draft", data);
    }
}
